/**
Interfaces for working with the Downloading system 
*/

namespace java hydrap2p.upload
namespace csharp hydrap2p.upload

include "service.thrift"
include "library.thrift"

struct UploadQueued {
	1:library.UID uid,		// the UID that is being uploaded
	2:library.Range requested,	// The range that is desired
	3:string name,			// The name of the file that wants to be uploaded
	4:i64 progress,			// How much of the file has been uploaded
	5:string ip,		// what IP this source has
	6:i32 port,			// what port this source has
	7:string protocol,	// what protocol this source is handled by
	8:string protocolInfo,	// any basic information that has special meaning for the protocol
}

service UploadProtocol extends service.Service {
	/**
	Tells the UploadProtocol that it is allowed to upload a piece of file
	*/
	void upload(1:UploadQueued upload),
	
	/**
	Cancels an outstanding upload
	*/
	void cancelUpload(1:UploadQueued upload),
}


service UploadListener extends service.Service {
	/**
	Tells any registered UploadListeners that more bytes have been uploaded
	*/
	oneway void updateUpload(1:UploadQueued upload),
	
	/**
	Notifies listeners that a new upload has been created
	*/
	oneway void newUpload(1:UploadQueued upload),
	
	/**
	Notifies listeners that an upload was removed
	*/
	oneway void removedUpload(1:UploadQueued upload),
	
}

/**
The Uploader is in charge of maintaining upload requests and deciding which ones should go next
*/
service Uploader extends service.Service {
	/**
		Registers a given protocol as available for uploading to
		Returns true if it was successfully added
	*/
	bool addUploadProtocol(1:service.ServiceLocation location, 2:string protocol),
	
	/**
		Unregisters a certain Upload Protocol module
		Returns true if it was deleted
	*/
	bool removeUploadProtocol(1:service.ServiceLocation location),
	
	/**
		Tries to enqueue a given upload request. Returns true if it worked
	*/
	bool enqueueUpload(1:UploadQueued upload),
	
	/**
		Gets the list of desired files
	*/
	list<UploadQueued> getUploadQueue(),
	
	/**
		Removes an upload from the queue, or from the list of active downloads.
		If the upload was currently in progress, it will free up an upload slot
		Returns true if the source was removed
	*/
	bool removeUpload(1:UploadQueued upload),
	
	/**
		Subscribes a component to receive updates about uploads
	*/
	void subscribeListener(1:service.ServiceLocation listener),
	
	/**
		Removes a component from receiving updates about uploads
	*/
	void unsubscribeListener(1:service.ServiceLocation listener),
	
	/**
		Used by the upload protocols to notify the Uploader, and indirectly any listeners, of changes to the upload
	*/
	void updateUpload(1:UploadQueued upload),
	
}
	
